package com.wenwan.manage.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wenwan.manage.service.ArticleCommentService;
import com.wenwan.manage.setting.DefaultValue;

import javax.annotation.Resource;

/**
 * 普通文章评论
 * 
 * @author Admin
 *
 */
@Controller
@RequestMapping(value = "/article/comment")
public class ArticleCommentController {

	@Autowired
	private ArticleCommentService articleCommentService;

	/**
	 * 评论一篇文章
	 * 
	 * @param content
	 *            评论内容
	 * @param articleId
	 *            文章ID
	 * @param userId
	 *            评论者ID
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/create", method = { RequestMethod.POST })
	public Map<String, Object> create(@RequestParam(required = true) String content,
			@RequestParam(required = true) String articleId, @RequestParam(required = true) String userId) {
		return articleCommentService.create(content, articleId, userId);
	}

	@ResponseBody
	@RequestMapping(value = "/delete/by/id", method = { RequestMethod.POST })
	public Map<String, Object> deleteById(@RequestParam(required = true) String id) {
		return articleCommentService.deleteById(id);
	}

	@ResponseBody
	@RequestMapping(value = "/update", method = { RequestMethod.POST })
	public Map<String, Object> update(@RequestParam(required = true) String id,
			@RequestParam(required = true) String content, @RequestParam(required = false) String articleId,
			@RequestParam(required = false) String userId) {
		return articleCommentService.update(id, content, articleId, userId);
	}

	@ResponseBody
	@RequestMapping(value = "/select/all", method = { RequestMethod.GET })
	public Map<String, Object> selectAll(
			@RequestParam(required = false, defaultValue = DefaultValue.CURRENT_PAGE) Integer currentPage,
			@RequestParam(required = false, defaultValue = DefaultValue.PAGE_SIZE) Integer pageSize,
			@RequestParam(required = true) String articleId) {
		return articleCommentService.selectAll(currentPage, pageSize, articleId);
	}

	@ResponseBody
	@RequestMapping(value = "/select/one/by/id", method = { RequestMethod.GET })
	public Map<String, Object> selectOneById(@RequestParam(required = true) String id) {
		return articleCommentService.selectOneById(id);
	}

}
